# python中的函数
def my_func(message):
    print("Got a message:{}".format(message))


my_func("测试自定义函数")


def my_sum(a, b):
    return a + b


a = 1
b = 2
print("my_sum:{}+{}={}".format(a, b, my_sum(a, b)))
print(my_sum([1, 2], [3, 4]))
print(my_sum('hello ', 'world'))


def find_largest_element(l):
    if not isinstance(l, list):
        print("input is not type of list")
        return
    if len(l) == 0:
        print("empty input")
        return
    largest_element = l[0]
    for item in l:
        if item > largest_element:
            largest_element = item
    print('largest_element is :{}'.format(largest_element))


find_largest_element([1, 5, 9, 2, 4, 10])


def nth_power(exponent):
    def exponent_of(base):
        return base ** exponent

    return exponent_of


square = nth_power(2)  # 计算一个数的平方
cube = nth_power(3)  # 计算一个数的立方
print(type(square))
print(type(cube))
print(square(2))  # 计算 2 的平方
print(cube(2))  # 计算 2 的立方
